home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 129_01.zip / 210MISC.C < prev    next >
Text File  |  1993-06-01  |  11KB  |  367 lines

  1. /************************************************************************/
  2. /*                misc.c                    */
  3. /*                                    */
  4. /*    Random functions...                        */
  5. /************************************************************************/
  6.  
  7. /************************************************************************/
  8. /*                history                 */
  9. /*                                    */
  10. /* 84Dec18 JLS    transmitFile() fixed so mAbort() affects <.rb> cmd.    */
  11. /* 84Dec17 JLS    Tutorial() fixed so on mabort() is stops instantly.    */
  12. /* 84Dec16 HAW    Tutorial() fixed so it can't access non-existent drives.*/
  13. /* 84Dec16 HAW&JLS download() & transmitFile() modified for new WC.    */
  14. /* 84Jul08 HAW    file_RO changed to detect R/O drives.            */
  15. /* 84Jul03 HAW    file_RO written to check .SYS files for R/O status.    */
  16. /* 84Jun23 HAW & JLS  patchDebug put under control of conditional comp. */
  17. /* 84Jun16 JLS & HAW  Configure fixed so that ".Enter Con..." works    */
  18. /* 84Jun10 JLS    Function changedate() installed.            */
  19. /* 84May01 HAW    Starting 1.50a upgrade.                 */
  20. /* 83Mar12 CrT    from msg.c                        */
  21. /* 83Mar03 CrT & SB   Various bug fixes...                */
  22. /* 83Feb27 CrT    Save private mail for sender as well as recipient.    */
  23. /* 83Feb23    Various.  transmitFile() won't drop first char on WC... */
  24. /* 82Dec06 CrT    2.00 release.                        */
  25. /* 82Nov05 CrT    Stream retrieval.  Handles messages longer than MAXTEXT.*/
  26. /* 82Nov04 CrT    Revised disk format implemented.            */
  27. /* 82Nov03 CrT    Individual history begun.  General cleanup.        */
  28. /************************************************************************/
  29.  
  30. #include <210ctdl.h>
  31.  
  32. /************************************************************************/
  33. /*                contents                */
  34. /*                                    */
  35. /*    changeDate()        allow changing of date            */
  36. /*    configure()        sets terminal parameters via dialogue    */
  37. /*    doCR()            newline on modem and console        */
  38. /*    download()        menu-level routine for WC-protocol sends*/
  39. /*    file_RO()        checks for file and drive being R/O    */
  40. /*    patchDebug()        display/patch byte            */
  41. /*    printDate()        prints out date             */
  42. /*    putFlChar()        readFile() -> disk file interface    */
  43. /*    putWCChar()        filter[]s, readFile() to putMsgChar()    */
  44. /*    transmitFile()        send a host file, no formatting     */
  45. /*    tutorial()        prints a .hlp file            */
  46. /*    upload()        menu-level read-via-WC-protocol fn    */
  47. /*    visible()        convert control chars to letters    */
  48. /************************************************************************/
  49.  
  50. /************************************************************************/
  51. /*    changedate() gets the date from the aide and remembers it    */
  52. /************************************************************************/
  53. changeDate()
  54. {
  55.     mPrintf("Current date is: ");
  56.     printdate();
  57.     if (!getYesNo("Enter a new date"))
  58.     return ;
  59.     interpret(pInitDate);
  60. }
  61.  
  62. /************************************************************************/
  63. /*    configure() sets up terminal width etc via dialogue        */
  64. /************************************************************************/
  65. configure() {
  66.     termWidth    = getNumber(" Screen width",          10, 255);
  67.     termNulls    = getNumber(" #Nulls",               0, 255);
  68.     termUpper    = getYesNo(" Uppercase only"             )    ?  UCMASK  :  0;
  69.     termLF    = getYesNo(" Linefeeds"              )    ?  LFMASK  :  0;
  70. /*  termTab    = getYesNo(" Tabs"                 )    ?  TABMASK :  0;
  71. */  expert    =!getYesNo(" Helpful hints"             )    ?  EXPERT  :  0;
  72.  
  73.     /* Now make it (only) semi-permanent     --JLS&HAW */
  74.     logBuf.lbwidth = termWidth;
  75.     logBuf.lbnulls = termNulls;
  76.     logBuf.lbflags = expert | termUpper | termLF | termTab | aide;
  77. }
  78.  
  79. /************************************************************************/
  80. /*    doCR() does a newline on modem and console            */
  81. /************************************************************************/
  82. doCR() {
  83.     int i;
  84.  
  85.     crtColumn    = 1;
  86.     if (outFlag) return;    /* output is being s(kip)ped    */
  87.  
  88.     putChar(NEWLINE);
  89.     if (haveCarrier) {
  90.     if (!usingWCprotocol) {
  91.         outmod('\r');
  92.         for (i=termNulls;  i;  i--) outmod(0);
  93.         if (termLF) outmod('\n');
  94.     } else {
  95.         sendWCChar('\r');
  96.         if (termLF) sendWCChar('\n');
  97.     }
  98.     }
  99. #ifdef XYZZY
  100. /* test code only */
  101.     else {
  102.     if (usingWCprotocol) {
  103.         sendWCChar('\r');
  104.         if (termLF) sendWCChar('\n');
  105.     }
  106.     }
  107. #endif
  108.     prevChar    = ' ';
  109. }
  110.  
  111. /************************************************************************/
  112. /*    download() is the menu-level send-message-via-WC-protocol fn    */
  113. /************************************************************************/
  114. download(whichMess, revOrder)
  115. char whichMess, revOrder;
  116. {
  117.     outFlag    = OUTOK;
  118.     if (!expert)   tutorial("wcdown.blb");
  119.  
  120.     outFlag    = OUTOK;
  121.     if (!getYesNo("Ready"))  return;
  122.  
  123.     /* here we go: */
  124.     echo        = NEITHER;
  125.     usingWCprotocol    = TRUE     ;    /* all points bulletin        */
  126.  
  127.     if (doWC(STARTUP))    {    /* Caller wasn't ready, so don't try    */
  128.  
  129.     showMessages(whichMess, revOrder);
  130.  
  131.     doWC(FINISH);            /* Clean up after the WC downloader     */
  132.     }
  133.  
  134.     setUp(FALSE);
  135.     usingWCprotocol    = FALSE  ;
  136. }
  137.  
  138. /************************************************************************/
  139. /*    file_RO() checks the given file for R/O status    --HAW        */
  140. /************************************************************************/
  141. file_RO(fd)
  142. int fd;
  143. {
  144. #define R_O_MASK    128
  145.     char *fc, *fcbaddr(), drive;
  146.     int  vector, bdos();
  147.  
  148.     if ((fc = fcbaddr(fd)) == ERROR)
  149.         return TRUE;        /* No such file, return  TRUE */
  150.     if ((fc[9] & R_O_MASK) != 0)
  151.         return TRUE;        /* Bit set, file is R/O */
  152.     /* else */
  153.     if ((drive = fc[0]) == 0)    /* Then get default disk from BDOS */
  154.         drive = bdos(25) + 1;
  155.                     /* Wheee!  Bit operations. */
  156.     vector = (bdos(29) << (16 - drive)) & 0x8000;
  157.     return vector;
  158. }
  159.  
  160. #ifdef XYZZY
  161. /************************************************************************/
  162. /*    patchDebug()                            */
  163. /************************************************************************/
  164. patchDebug() {
  165.     unsigned  i, j, page;
  166.     char      finished, *pc;
  167.  
  168.     mPrintf("\bpatch\n ");
  169.     page = getNumber("page", 0, 255);
  170.     finished = FALSE;
  171.     do {
  172.     for (i=16, pc= (page*256);  i;    i--)   {
  173.         mPrintf("%d ", pc);
  174.         for (j=16;    j;  j--)   {
  175.         mPrintf("%c", visible(*pc++));
  176.         }
  177.         mPrintf("\n ");
  178.     }
  179.     switch (toLower(iChar()))   {
  180.     case 'r':
  181.         pc    = getNumber("adr", 0, 65355);
  182.         *pc = getNumber("val", 0, 255);
  183.         break;
  184.     case 'n':    page++;         break;
  185.     case 'p':    page--;         break;
  186.     default:    finished = TRUE;    break;
  187.     }
  188.     } while (!finished);
  189. }
  190. #endif
  191. /************************************************************************/
  192. /*    printDate() prints out current date.                */
  193. /************************************************************************/
  194. printDate()
  195. {
  196.     mPrintf("%d%s%02d ", interpret(pGetYear),
  197.              monthTab[interpret(pGetMonth)],
  198.              interpret(pGetDay));
  199. }
  200.  
  201. /************************************************************************/
  202. /*    putFlChar() is used to upload files                */
  203. /*    returns: ERROR on problems else TRUE                */
  204. /*    Globals: msgBuf.mbtext is used as a buffer, to save space    */
  205. /************************************************************************/
  206. putFlChar(c)
  207. char c;
  208. {
  209.     return  putC(c, msgBuf.mbtext) != ERROR;
  210. }
  211.  
  212. /************************************************************************/
  213. /*    putWCChar() filter[]s from readFile() to putMsgChar()        */
  214. /*    Returns: ERROR if problems, else TRUE                */
  215. /*    Globals: outFlag is set to OUTSKIP when an ascii EOF (^Z) is    */
  216. /*        encountered, and no further text is written to disk.    */
  217. /************************************************************************/
  218. int putWCChar(c)
  219. int c;
  220. {
  221.     if (outFlag)    return TRUE;    /* past ascii EOF.  ignore.    */
  222.  
  223.     if (c == ERROR) {
  224.     /* EOF.  Note for overkill:    */
  225.     outFlag = OUTSKIP;
  226.     return TRUE;
  227.     }
  228.  
  229.     c    &= 0x7F;    /* cut high stuff off    */
  230.  
  231.     if (c == CPMEOF) {
  232.     /* ascii EOF.  Ignore rest of file:    */
  233.     outFlag = OUTSKIP;
  234.     return TRUE;
  235.     }
  236.  
  237.     return  putMsgChar(filter[c]);
  238. }
  239.  
  240. /************************************************************************/
  241. /*    transmitFile() dumps a host file with no formatting        */
  242. /************************************************************************/
  243. transmitFile(filename)
  244. char *filename;
  245. {
  246.     char mAbort();
  247.     int  getc(), sendWCChar();
  248.     char fbuf[BUFSIZ], fname[NAMESIZE];
  249.     int  c;
  250.  
  251.     outFlag    = OUTOK;
  252.  
  253.     unspace(filename, fname);
  254.  
  255.     if(fopen(fname, fbuf) == ERROR) {
  256.     mPrintf("\n No %s.\n", fname);
  257.     return(ERROR);
  258.     }
  259.  
  260.     doCR();
  261.     if (usingWCprotocol)   {
  262.     if (!doWC(STARTUP)) {
  263.         fClose(fbuf);
  264.         return ERROR;
  265.     }
  266.     }
  267.  
  268.     while ((c=getc(fbuf)) != ERROR)  {
  269.     if (!usingWCprotocol)
  270.         putChar(c);
  271.     if (whichIO == MODEM) {
  272.         if (!usingWCprotocol) outMod(c);
  273.         else if (!sendWCChar(c)) break;
  274.     }
  275.     if (textDownload      &&  c==CPMEOF)  break;
  276.     if (!usingWCprotocol  &&  mAbort())   break;
  277.     }
  278.  
  279.     if (usingWCprotocol)   doWC(FINISH);
  280.  
  281.     fClose(fbuf);
  282. }
  283.  
  284. /************************************************************************/
  285. /*    tutorial() prints file <filename> on the modem & console    */
  286. /*    Returns:    TRUE on success else ERROR            */
  287. /************************************************************************/
  288. #define MAXWORD 256
  289. tutorial(filename)
  290. char *filename;
  291. {
  292.     char fbuf[BUFSIZ];
  293.     int  c;
  294.     int  toReturn;
  295.  
  296.     toReturn    = TRUE;
  297.  
  298.     outFlag    = OUTOK;
  299.     if (filename[1] == ':' || fopen(filename, fbuf) == ERROR) {
  300.     mPrintf("\n No %s.\n", filename);
  301.     toReturn    = ERROR;
  302.     } else {
  303.     if (!expert)   mPrintf("\n <J>ump <P>ause <S>top\n");
  304.     mPrintf(" \n");
  305.     while ((c=getc(fbuf)) != ERROR)  {
  306.         putChar(c);
  307.         if (whichIO == MODEM)
  308.         outMod(c);
  309.         if (c==CPMEOF || mAbort())     break;
  310.     }
  311.     fClose(fbuf);
  312.     }
  313.  
  314.     return   toReturn;
  315. }
  316.  
  317. /************************************************************************/
  318. /*    upLoad() enters a file into current directory            */
  319. /************************************************************************/
  320. upLoad() {
  321.     char fileName[NAMESIZE], *s;
  322.     int putFlChar();
  323.  
  324.     getNormStr("filename", fileName, NAMESIZE);
  325.  
  326.     if (fileName[1] != ':')   s = &fileName[0];
  327.     else              s = &fileName[2];
  328.  
  329.  
  330.     setSpace(roomBuf.rbdisk, roomBuf.rbuser);
  331.  
  332.     if(fOpen(s, msgBuf.mbtext) != ERROR) {
  333.     mPrintf("\n A %s already exists.\n", s);
  334.     } else {
  335.     if (!expert) {
  336.         setSpace(homeDisk, homeUser);
  337.         tutorial("wcupload.blb");
  338.         setSpace(roomBuf.rbdisk, roomBuf.rbuser);
  339.     }
  340.     if (fCreat(s, msgBuf.mbtext) == ERROR) {
  341.         mPrintf("\n Can't create %s!\n", s);
  342.     } else {
  343.  
  344.         readFile(putFlChar);
  345.  
  346.         fFlush(msgBuf.mbtext);
  347.         fClose(msgBuf.mbtext);
  348.     }
  349.     }
  350.     setSpace(homeDisk, homeUser);
  351. }
  352.  
  353. /************************************************************************/
  354. /*    visible() converts given char to printable form if nonprinting    */
  355. /************************************************************************/
  356. char visible(c)
  357. char c;
  358. {
  359.     if (c==0xFF)  c = '$'    ;   /* start-of-message in message.buf    */
  360.     c            = c & 0x7F    ;   /* kill high bit otherwise        */
  361.     if ( c < ' ') c = c + 'A' -1;   /* make all control chars letters    */
  362.     if (c== 0x7F) c = '~'    ;   /* catch DELETE too         */
  363.     return(c);
  364. }
  365.  roomBuf.rbuser);
  366.  
  367.     if(fOpen(s, msgBuf.mbtex